import java.sql.Array;
import java.util.ArrayList;
import java.util.List;

/**
 * @author malguy-wang sir
 * @create ---
 */
public class myArrayListHashMap<K,V> implements myMap<K,V>{
    private int size;
    private List<Node> list = new ArrayList<>();
    @Override
    public int size() {
        return size;
    }
    @Override
    public V get(K key) {
        return getNode(key).value;
    }
    private Node getNode(K key){//根据key查询
        for (Node node : list) {
            if(key.equals(node.key)){
                return node;
            }
        }
        return null;
    }
    @Override
    public V put(K key, V value) {
        //如果key已经存在,直接修改
        Node node1 = getNode(key);
        if(node1!=null){
            node1.value = value;
            return node1.getValue();
        }
        Node node = new Node(key, value);
        list.add(node);
        size++;
        return value;
    }
    private class Node implements entry<K,V>{
        public Node(K key, V value) {
            this.key = key;
            this.value = value;
        }
        private K key;
        private V value;
        @Override
        public K getKey() {
            return key;
        }
        @Override
        public V getValue() {
            return value;
        }
    }
}
